﻿using System.Collections.Generic;
using System.Linq;
using Apps.Web.Core;
using Apps.IBLL.LMS;
using Apps.Locale;
using System.Web.Mvc;
using Apps.Common;
using Apps.IBLL;
using Microsoft.Practices.Unity;
using Newtonsoft.Json.Linq;
using Newtonsoft.Json;
using System;
using System.Data;
using Apps.Models;
using Apps.BLL.YANX;

namespace Apps.Web.Areas.LMS.Controllers
{
    public class TestDataQueryController : BaseController
    {
        [Dependency]
        public ILMS_TESTDATA_CONFIRMEDBLL m_BLL { get; set; }
        ValidationErrors errors = new ValidationErrors();

        [SupportFilter]
        public ActionResult Index()
        {
            return View();
        }

        [HttpPost]
        [SupportFilter(ActionName = "Index")]
        public JsonResult GetList(GridPager pager, string batch, string sample, string lms, string startdate, string enddate, string TYPE_STR = "")
        {
            List<V_LMS_QUERY_RCModel> list = m_BLL.GetList(ref pager, batch, sample, lms, startdate, enddate, TYPE_STR);
            GridRows<V_LMS_QUERY_RCModel> grs = new GridRows<V_LMS_QUERY_RCModel>();
            grs.rows = list;
            grs.total = pager.totalRows;
            return Json(grs);
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public ActionResult Yanx(string id)//id为AUDIT_ID
        {
            YANX_RECORD_BLL yanxBll = new YANX_RECORD_BLL();
            return View(yanxBll.GetAllList(id));
        }

        [HttpPost]
        [SupportFilter(ActionName = "Index")]
        public JsonResult GetListDetail(GridPager pager, string testCode, string code)
        {
            List<V_LMS_TESTDATA_CONFIRMEDModel> list = m_BLL.GetListDetail(ref pager, testCode, code);
            GridRows<V_LMS_TESTDATA_CONFIRMEDModel> grs = new GridRows<V_LMS_TESTDATA_CONFIRMEDModel>();
            for (int i = 0; i < list.Count; i++)
            {
                list[i].USERNAME = list[i].USERNAME == "超级管理员" ? "值班长" : list[i].USERNAME;
            }
            grs.rows = list;
            grs.total = pager.totalRows;
            return Json(grs);
        }
    }
}
